package com.tomecode.rvr;

import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;

import com.tomecode.rvr.generator.Config;
import com.tomecode.rvr.generator.ReportGenerator;

/**
 * 
 * Maven plugin for generate report file
 * 
 * @author Frastia Tomas
 * 
 * @goal generateReport
 */
public final class RepositoryVersionReporterPlugin extends AbstractMojo {

	// init repository
	static {
		// DAVRepositoryFactory.setup();
		SVNRepositoryFactoryImpl.setup();
		// FSRepositoryFactory.setup();
	}

	/**
	 * Contain configuration for plugin
	 * 
	 * @parameter
	 */
	private Config config;

	public final void execute() throws MojoExecutionException, MojoFailureException {
		getLog().info("generate working copy info:start");

		try {
			ReportGenerator reportGenerator = new ReportGenerator(config);
			reportGenerator.generate();
		} catch (IOException e) {
			getLog().error("failed generate report, reason: " + e.getMessage(), e);
			throw new MojoExecutionException("failed generate report, reason: " + e.getMessage(), e);
		}
		getLog().info("generate working copy info:end");
	}

}
